/**
 * 
 */
package cn.softTank.BpelModelImpl;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import cn.softTank.BpelModel.JoinCondition;
import cn.softTank.BpelModel.Target;
import cn.softTank.BpelModel.Targets;

/**
 * @author Yuzone (smartzxy@gmail.com)
 * 
 */
public class TargetsImpl implements Targets {

	private JoinCondition joinCondition;
	private List<Target> target;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.softTank.BpelModel.Targets#addTarget(cn.softTank.BpelModel.Target)
	 */
	@Override
	public void addTarget(Target target) {
		if (this.target == null)
			this.target = new ArrayList<Target>();
		this.target.add(target);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Targets#getJoinCondition()
	 */
	@Override
	public JoinCondition getJoinCondition() {
		return joinCondition;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Targets#getTarget()
	 */
	@Override
	public List<Target> getTarget() {
		return target;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Targets#removeTargetAt(int)
	 */
	@Override
	public void removeTargetAt(int index) {
		if (target != null && index < target.size())
			target.remove(index);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.softTank.BpelModel.Targets#setJoinCondition(cn.softTank.BpelModel.
	 * JoinCondition)
	 */
	@Override
	public void setJoinCondition(JoinCondition joinCondition) {
		this.joinCondition=joinCondition;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.Targets#setTarget(java.util.List)
	 */
	@Override
	public void setTarget(List<Target> target) {
		this.target=target;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.XmlAdapt#toElement()
	 */
	@Override
	public Element toElement() {
		Element e=DocumentHelper.createElement("targets");
		if(joinCondition!=null)
			e.add(joinCondition.toElement());
		if(target!=null)
			for(int i=0; i<target.size(); i++)
				e.add(target.get(i).toElement());
		return e;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see cn.softTank.BpelModel.XmlAdapt#toXml()
	 */
	@Override
	public String toXml() {
		// TODO Auto-generated method stub
		return null;
	}

}
